import { Body, Controller, DefaultValuePipe, Delete, Get, Param, Post, Put, Query } from '@nestjs/common'
import { generateParseIntPipe } from 'src/utils'
import { RequireLogin } from 'src/custom/decorator'
import { MeetingService } from './meeting.service'
import { CreateMeetingDto } from './dto/create-meeting.dto'
import { UpdateMeetingDto } from './dto/update-meeting.dto'

@Controller('meeting')
export class MeetingController {
  constructor(private readonly meetingService: MeetingService) {}

  @Get('init-data')
  async initData() {
    await this.meetingService.initData()
    return 'init done'
  }

  @Get('list')
  async list(
    @Query('pageNo', new DefaultValuePipe(1), generateParseIntPipe('pageNo')) pageNo: number,
    @Query('pageSize', new DefaultValuePipe(2), generateParseIntPipe('pageSize')) pageSize: number,
    @Query('name') name: string,
    @Query('capacity') capacity: number,
    @Query('equipment') equipment: string,
  ) {
    return await this.meetingService.find(pageNo, pageSize, name, capacity, equipment)
  }

  @Post('create')
  async create(@Body() meetingDto: CreateMeetingDto) {
    return await this.meetingService.create(meetingDto)
  }

  @Put('update')
  async update(@Body() meetingDto: UpdateMeetingDto) {
    return await this.meetingService.update(meetingDto)
  }

  @Get(':id')
  async find(@Param('id') id: number) {
    return await this.meetingService.findById(id)
  }

  @Delete(':id')
  @RequireLogin()
  async delete(@Param('id') id: number) {
    return await this.meetingService.delete(id)
  }
}
